<style lang='less'>
  .back-img {
    background-image: url('../../../assets/yiqing/hs-back2.png');
    background-position: center;
  }
  .back-img2 {
    background-image: url('../../../assets/yiqing/hs-back1.png');
    background-position: center;
  }
  .back-img1 {
    background-image: url('../../../assets/yiqing/hs-back3.png');
    background-position: center;
  }
  .tips-menu-v1 .desc {
    font-size: 16px;
    font-weight: 500;
    // margin-bottom: 5px;
    // margin-top: 5px;
  }
</style>
<template>
    <div class="container">
      <Row :gutter="16" class="tips-menu-v1" style="margin-bottom: 10px;">
        <Col span="8">
          <Card style="" class="back-img1">
            <div style="text-align:center">
              <div class="desc"><span style="color:white">采样数量：</span><span style="color:red;font-size:20px"> {{count.count1}} </span><span style="color:white">人</span></div>
            </div>
          </Card>
        </Col>
        <Col span="8">
          <Card style="" class="back-img2">
            <div style="text-align:center">
              <div class="desc"><span style="color:white">已送检数量：</span><span style="color:red;font-size:20px"> {{count.count2}} </span><span style="color:white">份</span></div>
            </div>
          </Card>
        </Col>
        <Col span="8">
          <Card style="" class="back-img">
            <div style="text-align:center">
              <div class="desc"><span style="color:white">阳性结果数量：</span><span style="color:red;font-size:20px"> {{count.count3}} </span><span style="color:white">份</span></div>
            </div>
          </Card>
        </Col>
        <!-- <Col span="8">
          <router-link to="">
            <div class="nc">
              <div class="desc">
                采集样品
              </div>
              <div class="num">{{accountingNum.remain_num || 0}}份</div>
            </div>
          </router-link>
        </Col>
        <Col span="8">
          <router-link to="">
            <div class="ic">
              <div class="desc">
                送检样品
              </div>
              <div class="num">{{accountingNum.all_num || 0}}份</div>
            </div>
          </router-link>
        </Col> -->
      </Row>
      <!-- <svg id="barcode" /> -->
        <div class="opt-area-02">
            <div class="right-con">
              <div class="input-frame" style="width: 200px">
                  <DatePicker type="date" placeholder="选择时间开始" v-model="start_time" style="width: 200px"></DatePicker>
              </div>
              <div class="input-frame" style="width: 200px">
                  <DatePicker type="date" placeholder="选择结束开始" v-model="end_time" style="width: 200px"></DatePicker>
              </div>
              <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px">搜索</Button>
            </div>
        </div>
        <Table :loading="countData.loading" :columns="columns1" :data="fcDataList" size="small" ref="table" border>
            <template slot="action" slot-scope="{ row }">
                <Row style="margin-bottom: 5px; margin-top: 2px">
                    <Button class="table-action-btn" type="info" size="small" v-if="row.num == 0" @click="deleteAppoint(row)">删除</Button>
                    <Button class="table-action-btn" type="success" size="small" @click="showdetail(row, 'edit')">编辑</Button>
                    <Button class="table-action-btn" type="success" size="small" @click="appointdetail(row)" style="margin-top:2px">预约详情</Button>
                </Row>
            </template>
        </Table>
        <!-- <Row v-if="loadData == true">
          <Col class="demo-spin-col" span="8" offset="8">
            <Spin fix>
              <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
              <div>Loading</div>
            </Spin>
          </Col>
        </Row> -->
        <Row type="flex" justify="end" class="page_style">
          <Page :current="currentPageNo" :total="totalnum" show-sizer :page-size="currentPageSize"
                show-total @on-change="changePageNo" @on-page-size-change="pageSizeChange"/>
        </Row>
        <Modal v-model="personShow" title="预约人员明细" width="1000" :closable="false">
          <Table border :columns="columns2" :data="data2">
            <template slot-scope="{ row }" slot="state">
              <span v-if="row.state == '0'">未取消</span>
              <span v-if="row.state == '1'">已取消</span>
            </template>
          </Table>
          <Row type="flex" justify="end" class="page_style">
            <Page :current="currentPageNo1" :total="totalnum1" :page-size="currentPageSize1"
                  show-total @on-change="changePageNo1"/>
          </Row>
        </Modal>
        <Modal v-model="appointObj.modal" :title="appointObj.title" @on-ok="okAppoint" @on-cancel="cancelAppoint">
          <Form label-position="right" :label-width="100">
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">预约时间段开始时间：</Col>
              <Col span="14" class="ivu-form-item-content">
                <DatePicker type="datetime" v-model="appoint_start_time" placeholder="请选择预约时间段开始时间" style="width: 285px"></DatePicker>
              </Col>
            </Row>
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">预约时间段结束时间：</Col>
              <Col span="14" class="ivu-form-item-content">
                <DatePicker type="datetime" v-model="appoint_end_time" placeholder="请选择预约时间段结束时间" style="width: 285px"></DatePicker>
              </Col>
            </Row>
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">可预约总人数：</Col>
              <Col span="14" class="ivu-form-item-content">
                <Input type="number" v-model="formItem.total"></Input>
              </Col>
            </Row>
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">预约开始时间：</Col>
              <Col span="14" class="ivu-form-item-content">
                <DatePicker type="datetime" v-model="start_time" placeholder="请选择预约开始时间" style="width: 285px"></DatePicker>
              </Col>
            </Row>
            <Row class="mb20">
              <Col span="7" class="ivu-form-item-label">预约结束时间：</Col>
              <Col span="14" class="ivu-form-item-content">
                <DatePicker type="datetime" v-model="end_time" placeholder="请选择预约结束时间" style="width: 285px"></DatePicker>
              </Col>
            </Row>
          </Form>
        </Modal>
        <!-- <barcode :value="barcodes" id="aaa" :options="barcode_option" tag="svg" ></barcode> -->
    </div>
</template>

<script>
import {
  createAppointSetting,
  updateAppointSetting,
  getAppointSettingList,
  getAppointPersonList,
  deleteAppointSetting,
  getCountJiGouHuiZong
} from '@/api/nucleic-acid-detection'
// import JsBarcode from 'jsbarcode'
// import VueBarcode from '@xkeshi/vue-barcode'
import { date0str } from '@/api/eventlist'
// import { config } from 'vue/types/umd'
// import { getCityList } from '@/api/common'
// import { forEach } from '@/libs/tools'
export default {
  name: 'list',
  data () {
    return {
      count: {
        count1: 0,
        count2: 0,
        count3: 0,
        count4: 0,
        count5: 0
      },
      appoint_code: '',
      flag: '',
      appoint_start_time: '',
      appoint_end_time: '',
      start_time: '',
      end_time: '',
      errorTitle: '错误',
      formItem: {},
      dateArr: [], // 时间数组
      appointObj: {
        modal: false,
        title: '预约设置'
      },
      barcode_option: {
        displayValue: true, // 是否默认显示条形码数据
        // textPosition:'top', //条形码数据显示的位置
        background: '#fff', // 条形码背景颜色
        valid: function (valid) {
          console.log(valid, '11@@@@')
        },
        width: '1px', // 单个条形码的宽度
        height: '55px',
        fontSize: '22px' // 字体大小
      },
      barcodes: 'LM208861606907720718',
      personShow: false,
      sampleObj: {
        modal1: false, // 修正结果模态框
        sample_result: '',
        sample_code: ''
      },
      loadData: false,
      countData: {
        loading: false
      },
      searchInfo: {},
      params: {
        pageNo: 1,
        pageSize: 10,
        appoint_code: ''
      },
      params1: {
        pageNo: 1,
        pageSize: 10,
        sample_code: '',
        sample_status: '',
        sample_result: ''
      },
      currentPageNo: 1,
      currentPageSize: 10,
      totalnum: 0,
      currentPageNo1: 1,
      currentPageSize1: 10,
      totalnum1: 0,
      columns1: [
        // { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '检测机构', key: 'send_company_name', align: 'center' },
        { title: '采样数量', key: 'yang_pin_shu_liang', align: 'center' },
        { title: '已送检数量', key: 'yi_song_jian_shu_liang', align: 'center' },
        { title: '地区', key: 'checked_num', align: 'center' },
        { title: '阳性结果数量', key: 'yang_xing_shu_liang', align: 'center' }
      ],
      fcDataList: [],
      columns2: [
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '姓名', key: 'name', width: 80, align: 'center' },
        { title: '证件号码', key: 'card_no', align: 'center' },
        { title: '联系电话', key: 'mobile', align: 'center' },
        { title: '详细地址', key: 'address', align: 'center' },
        { title: '预约状态', slot: 'state', align: 'center' },
        { title: '预约时间', key: 'appoint_create_time', align: 'center' }
      ],
      data2: [] // 预约人明细列表
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  watch: {
  },
  methods: {
    init () {
      getCountJiGouHuiZong().then(res => {
        if (res.data.errcode === 0) {
          this.fcDataList = res.data.data
          let that = this
          this.fcDataList.forEach(function (temp) {
            if (temp.checked_num === undefined) {
              temp.checked_num = temp.send_company_name.substring(0, temp.send_company_name.length - 4)
            }
            that.count.count1 = that.count.count1 + temp.yang_pin_shu_liang
            that.count.count2 = that.count.count2 + temp.yi_song_jian_shu_liang
            that.count.count3 = that.count.count3 + temp.yang_xing_shu_liang
          })
          this.fcDataList = res.data.data
        } else {
          this.$Notice.error({
            title: '查询失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    setAppoint (flag) { // 设置预约
      this.flag = flag
      this.formItem = {}
      this.start_time = ''
      this.end_time = ''
      this.appoint_start_time = ''
      this.appoint_end_time = ''
      this.appointObj.modal = true
    },
    okAppoint () { // 保存预约
      this.formItem.appoint_company_code = this.companyCode
      this.formItem.appoint_start_time = date0str(this.appoint_start_time)
      this.formItem.appoint_end_time = date0str(this.appoint_end_time)
      this.formItem.start_time = date0str(this.start_time)
      this.formItem.end_time = date0str(this.end_time)
      if (this.formItem.appoint_start_time === '' || this.formItem.appoint_start_time === undefined) {
        const content = '<p>请选择时间段开始时间</p>'
        this.$Modal.error({
          title: this.errorTitle,
          content: content
        })
        return
      }
      if (this.formItem.appoint_end_time === '' || this.formItem.appoint_end_time === undefined) {
        const content = '<p>请选择时间段结束时间</p>'
        this.$Modal.error({
          title: this.errorTitle,
          content: content
        })
        return
      }
      if (this.formItem.total === '' || this.formItem.total === undefined) {
        const content = '<p>请填写可预约总人数</p>'
        this.$Modal.error({
          title: this.errorTitle,
          content: content
        })
        return
      }
      if (this.formItem.start_time === '' || this.formItem.start_time === undefined) {
        const content = '<p>请选择预约开始时间</p>'
        this.$Modal.error({
          title: this.errorTitle,
          content: content
        })
        return
      }
      if (this.formItem.end_time === '' || this.formItem.end_time === undefined) {
        const content = '<p>请选择预约结束时间</p>'
        this.$Modal.error({
          title: this.errorTitle,
          content: content
        })
        return
      }
      var url = ''
      if (this.flag === 'add') {
        url = createAppointSetting
      } else if (this.flag === 'edit') {
        url = updateAppointSetting
      }
      url(this.formItem).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({
            title: '设置预约成功',
            desc: res.data.errmsg
          })
          this.appointObj.modal = false
          this.getList()
        } else {
          this.$Notice.error({
            title: '设置预约失败',
            desc: res.data.errmsg
          })
          this.getList()
          // console.log(this.fcDataList, 'leibiao ')
        }
      })
    },
    cancelAppoint () { // 关闭预约
      this.appointObj.modal = false
    },
    showdetail (item, flag) { // 编辑
      this.flag = flag
      this.appointObj.modal = true
      this.formItem = item
      this.appoint_start_time = this.formItem.appoint_start_time
      this.appoint_end_time = this.formItem.appoint_end_time
      this.start_time = this.formItem.start_time
      this.end_time = this.formItem.end_time
    },
    appointdetail (item) { // 预约详情
      this.personShow = true
      this.appoint_code = item.appoint_code
      this.getPersonList(item.appoint_code, 1)
    },
    deleteAppoint (item) { // 删除预约
      if (confirm('确定删除吗')) {
        deleteAppointSetting({ appoint_code: item.appoint_code }).then(res => {
          if (res.data.errcode === 0) {
            this.$Notice.success({
              title: '删除成功',
              desc: res.data.errmsg
            })
            this.getList()
          } else {
            this.$Notice.error({
              title: '删除失败',
              desc: res.data.errmsg
            })
          }
        })
      }
    },
    pageAction (page) {
      this.params.pageNo = page
      this.getList()
    },
    selectlist () {
      this.params.pageNo = 1
      this.getList()
    },
    getList () {
      getAppointSettingList(this.params).then(res => {
        if (res.data.errcode === 0) {
          this.fcDataList = res.data.data.results
          this.totalnum = res.data.data.totalRecord
        } else {
          this.$Notice.error({
            title: '查询列表信息失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    changePageNo (pageNo) {
      console.log(pageNo, '页数')
      this.currentPageNo = pageNo
      this.params.pageNo = pageNo
      this.getList(this.params)
    },
    changePageNo1 (pageNo) { // 预约人员列表
      console.log(pageNo, '页数')
      this.currentPageNo1 = pageNo
      this.params1.pageNo = pageNo
      this.getPersonList(this.appoint_code, pageNo)
    },
    getPersonList (appoint_code, pageNo) { // 获取送检人列表
      let param = {
        appoint_code: appoint_code,
        pageNo: pageNo,
        pageSize: 10
      }
      getAppointPersonList(param).then(res => {
        if (res.data.errcode === 0) {
          this.data2 = res.data.data.results
          this.totalnum1 = res.data.data.totalRecord
          console.log(this.data2, '明细列表')
        } else {
          this.$Notice.error({
            title: '获取预约人员列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    pageSizeChange (e) {
      this.params.pageSize = e
      this.selectlist(this.params.pageNo)
    },
    cancel () {
      this.personShow = false
    }
    // handleSummary ({ columns, data }) {
    //   const sums = {}
    //   columns.forEach((column, index) => {
    //     console.log(column, ':summary-method="handleSummary"')
    //     const key = column.key
    //     if (index === 0) {
    //       sums[key] = {
    //         key,
    //         value: '总价'
    //       }
    //       return
    //     }
    //     const values = data.map(item => Number(item[key]))
    //     // if (!values.every(value => isNaN(value))) {
    //     //   const v = values.reduce((prev, curr) => {
    //     //     const value = Number(curr)
    //     //     if (!isNaN(value)) {
    //     //       return prev + curr
    //     //     } else {
    //     //       return prev
    //     //     }
    //     //   }, 0)
    //     //   sums[key] = {
    //     //     key,
    //     //     value: v + ' 元'
    //     //   }
    //     // } else {
    //     //   sums[key] = {
    //     //     key,
    //     //     value: 'N/A'
    //     //   }
    //     // }
    //   })
    //   return sums
    // }
  },
  mounted () {
    this.init()
    // var aa = document.getElementById('aaa')
    // this.getList()
    // JsBarcode('#barcode', '61606924060795', {
    //   format: 'CODE128',
    //   lineColor: '#000',
    //   background: '#EBEEF5',
    //   width: 0.5,
    //   height: 40,
    //   displayValue: false
    // })
  }
}
</script>

<style scoped>
    .page_style {
        margin: 20px 5px;
    }

    .input-frame {
        width: 120px;
        margin-right: 10px;
    }

    .house-list > .group {
        background: white;
        padding: 10px;
        margin-top: 10px;
    }

    .house-list > .group > .item {
        border-bottom: 1px solid #f5f5f5;
        padding: 10px 0;
    }

    .house-list > .group > .item .top {
        display: flex;
        justify-content: space-between;
        margin-bottom: 5px;
    }

    .house-list > .group > .item .title {
        font-size: 14px;
        color: #333333;
    }

    .house-list > .group > .item .address {
        font-size: 12px;
        color: gray;
        display: flex;
        align-items: center;
    }

    .house-list > .group > .item .detail {
        font-size: 12px;
        color: dodgerblue;
    }

    .opt-area-02 {
        display: flex;
        align-items: center;
        flex-direction: column;
        border: 1px solid #abdcff;
        background-color: #f0faff;
        padding: 8px 16px 8px 16px;
        border-radius: 4px;
        margin-bottom: 10px;
    }

    .opt-area-02 .right-con {
        width: 100%;
        margin-top: 5px;
        display: flex;
    }

    .opt-area-02 .left-con {
        font-size: 14px;
        width: 100%;
    }

    .opt-area-02 .left-con span {
        font-weight: bold;
    }

    .opt-area-02 .right-con input {
        width: 150px;
        margin-right: 10px;
    }

    .opt-area-02 .right-con .input-frame {
        width: 200px;
        margin-right: 10px;
    }

    .table-action-btn {
        margin-right: 3px;
    }

    .container >>> .ivu-btn-small {
        height: 24px;
        padding: 0 5px;
        font-size: 12px;
        border-radius: 3px;
    }

    .btn-action {
        margin-bottom: 10px;
    }

    .mp10 {
        margin-right: 10px;
    }
    .title-style {
      color: red;
    }
    .mb20 {
      margin-bottom: 20px;
    }
    .mt20 {
      margin-top: 20px;
    }
    .ivu-table-row {
      height: 57px;
    }
  .ivu-form-item-label {
    margin-top: 8px;
  }
    .demo-spin-icon-load{
      animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
      from { transform: rotate(0deg);}
      50%  { transform: rotate(180deg);}
      to   { transform: rotate(360deg);}
    }
    .demo-spin-col{
      height: 100px;
      position: relative;
      /*border: 1px solid #eee;*/
    }
</style>
